<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" id="teacherForm">
<head>
    <title>虚机设定</title>
    <script type="text/javascript">
    var mainform;
    var viewType = "${viewType}";

    $(document).ready(function ()
   	{
        mainform=$("#mainform");
        
        mainform.ligerForm();
        
        if(viewType=="modify"){
			$("#id").attr("readonly", "readonly").removeAttr("validate");
        }
        
        //如果是详细试图,所有字段不可编辑
        if(viewType=="detail"){
        	$("input,select,textarea",mainform).attr("readonly", "readonly");
        }else{
            $.metadata.setType("attr", "validate");
            LG.validate(mainform);
        }
        
        $.validator.addMethod('IP4Checker', function(value) {
        	var re = /^((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))$/;

     		if(re.test(value))
    			return true;
    		else  
    			return false;
            }, 'IP地址格式有误');
        
        //渲染按钮
        LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : save);

    });
   
    function save(){

        LG.submitForm(mainform, function (result) {
        	if(typeof(result)=="string"){
        		result=eval("("+result+")");
        	}
            if (!result.success) {
                LG.showError('错误:' + result.message);
            }
            else { 
                LG.showSuccess('保存成功', function () { 
                   LG.callParent("clsList");
                });
            }
        });
    }
    
    function cancel(){
        var win = window.parent || window;
        if(win.dialog){
        	win.dialog.close();
        }
    }
 </script>
</head>

<body>
    <form name="mainform" method="post" id="mainform" action="${ctx}/qso/vm/save">
        <input type="hidden" name="viewType" value="${viewType}"/>
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 90%; margin-top:10px; margin-left:15px;">
            <tr>
                <td align="right" class="l-table-edit-style="width: 15%">虚机编号:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	${command.id}
                	<input name="id" type="hidden" id="id" value="${command.id}" ltype="text" />
                </td>
                <td align="right" class="l-table-edit-td" style="width: 15%">虚机名称:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input type="text" name="name" id="name" value="${command.name}" ltype="text" validate="{required:true, notnull:true}" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" style="width: 15%">IP地址:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input name="ip" type="text" id="ip" value="${command.ip}" ltype="text" validate="{required:true, notnull:true, IP4Checker:true}"  nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>  />
                </td>
                <td align="right" class="l-table-edit-td" style="width: 15%">VNC密码:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input name="pwd" type="text" id="pwd" value="${command.pwd}" ltype="text" validate="{required:true, notnull:true}" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td>
            </tr>
            <!-- 
            <tr>
                <td align="right" class="l-table-edit-td" style="width: 15%">MAC位置:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input name="mac" type="text" id="mac" value="${command.mac}" ltype="text" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td>
                <td align="right" class="l-table-edit-td" style="width: 15%">虚机域名:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input name="ad" type="text" id="ad" value="${command.ad}" ltype="text" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td>
            </tr> 
             -->
            <tr>
            	<td align="right" class="l-table-edit-td" style="width: 15%">端口号:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input name="port" type="text" id="port" value="${command.port}" ltype="text" validate="{required:true, digits:true}" maxlength="5" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td>
                <td align="right" class="l-table-edit-td" style="width: 15%">是否启用:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<select style="width: 180px" name="isEnable" id="isEnable" ltype="select" validate="{required:true}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                	<c:if test="${viewType!='add'}">
                		<option value="T" selected="${command.isEnable == T}">是</option>
              			<option value="F" selected="${command.isEnable == F}">否</option>
              		</c:if>	
              		<c:if test="${viewType=='add'}">
              			<option value="T" selected="true">是</option>
              			<option value="F">否</option>
              		</c:if>	
                	 </select> 
                </td>
            </tr>  
            <tr>
            	<td align="right" class="l-table-edit-td" style="width: 15%">备注:</td>
                <td align="left" class="l-table-edit-td" style="width: 35%">
                	<input name="desc" type="text" id="desc" value="${command.desc}" ltype="text" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td> 
            </tr>
        </table>
    </form>
</body>
</html>
